AC_INIT([wgl], [0.0.0])
AC_CONFIG_AUX_DIR([acaux])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h:config.h.in])
AM_INIT_AUTOMAKE

: ${CXXFLAGS:=-Wall -std=c++20}

AC_PROG_CXX
LT_INIT([win32-dll])

AC_PROG_LN_S
AC_PROG_MKDIR_P

AC_SUBST([glmincludedir], ['${pkgincludedir}/glm'])
AC_SUBST([pkgconfigdir], ['${libdir}/pkgconfig'])

# --enable-debug
AC_ARG_ENABLE(
    [debug],
    AS_HELP_STRING([--enable-debug], [Enable debug @<:@default=yes@:>@]),
    [wgl_enable_debug=${enableval}],
    [wgl_enable_debug=yes]
)

AS_CASE(
    [${wgl_enable_debug}],
    [yes], [wgl_debug_flags='-g -O0 -DWGL_DEBUG'],
    [no],  [wgl_debug_flags='-O2 -DNDEBUG'],
    [AC_MSG_ERROR([wgl_enable_debug: wrong value: ${wgl_enable_debug}])]
)

# --enable-gprof
AC_ARG_ENABLE(
    [gprof],
    AS_HELP_STRING([--enable-gprof], [Enable gprof compile flags @<:@default=no@:>@]),
    [wgl_enable_gprof=${enableval}],
    [wgl_enable_gprof=no]
)

AS_CASE(
    [${wgl_enable_gprof}],
    [yes], [wgl_gprof_flags='-pg'; wgl_gprof_libs='-pg'],
    [no],  [wgl_gprof_flags=''; wgl_gprof_libs=''],
    [AC_MSG_ERROR([wgl_enable_gprof: wrong value: ${wgl_enable_gprof}])]
)

# --enable-boost
AC_ARG_ENABLE(
    [boost],
    AS_HELP_STRING([--enable-boost], [Enable use of boost libs @<:@default=yes@:>@]),
    [wgl_enable_boost=${enableval}],
    [wgl_enable_boost=yes]
)

AX_BOOST_BASE([1.63])

# --enable-install-symlink
#
# NOTE: weird and dirty hack, remember to try distcheck with
# default=yes, just in case
#
AC_ARG_ENABLE(
    [install-symlink],
    AS_HELP_STRING([--enable-install-symlink], [Install files as symlinks @<:@default=no@:>@]),
    [wgl_install_symlink=${enableval}],
    [wgl_install_symlink=no]
)

AM_CONDITIONAL([WGL_INSTALL_SYMLINK], [test x$wgl_install_symlink = xyes])

#
AS_CASE(
    [${host}],
    [*-mingw32], [wgl_static_gcc_ldflags='-static-libgcc -static-libstdc++'],
    [wgl_static_gcc_ldflags='']
)

AC_SUBST([WGL_CFLAGS], ["$wgl_debug_flags $wgl_gprof_flags"])
AC_SUBST([WGL_LDFLAGS], ["$wgl_static_gcc_ldflags"])
AC_SUBST([WGL_LIBS], ["$wgl_gprof_libs"])

PKG_CHECK_MODULES([SDL], [sdl2])

# python/pylint
AC_MSG_CHECKING([python3])
AC_PATH_PROG([PYTHON], [python3])
AC_MSG_RESULT([$PYTHON])
AC_ARG_VAR([PYTHON], [path of the python3 executable])

AC_ARG_VAR([PYLINT], [path of the pylint executable])
AC_SUBST([PYLINT])
AC_MSG_CHECKING([pylint])
AC_PATH_PROG([PYLINT], [pylint])
AC_MSG_RESULT([$PYLINT])

if test x"$PYTHON" = x; then
    AC_MSG_WARN([python3 not found])
fi

AC_CONFIG_FILES([ \
  wgl.pc \
  Makefile \
  wglmkapplayer/Makefile \
  wgl/Makefile \
])
AC_OUTPUT
